<?php

class User_Controller_Browse_Ajax_Setting_Email extends Nuo_Controller_Resolver
{

	function doForm($request)
	{
		$user = Nuo::getUser();
		return  array('html' => Nuo::getView()->render('user/view/controller/browse/ajax/setting/email/form', array('user' => $user)));
	}

	function doCancel($request)
	{
		$user = Nuo::getUser();
		return  array('html' => Nuo::getView()->render('user/view/controller/browse/ajax/setting/email/cancel', array('user' => $user)));
	}

	function doSubmit($request)
	{

		$username = $_POST['username'];
		$user = Nuo::getUser();

		$api = Nuo::getApi('membership');

		if ($api -> addAlias($user, $username))
		{
			$user -> username = $username;
			$user -> save();
			return  array('html' => Nuo::getView()->render('user/view/controller/browse/ajax/setting/email/cancel', array(
					'user' => $user,
					'msg' => NULL
				)));
		}
		else
		{
			return  array('html' => Nuo::getView()->render('user/view/controller/browse/ajax/setting/email/cancel', array(
					'user' => $user,
					'msg' => 'This username is invalid or is exists!'
				)));
		}

	}

}
